package lily.phs.mental;

import lily.phs.object.HereTipa;
import lily.phs.object.VisitMentals;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;
import android.content.Context;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.LinearLayout.LayoutParams;

public class VisitMentalsView_1 extends LinearLayout implements OnClickListener, OnFocusChangeListener{

	private Context mContext;
	private EditText et_name,et_id,et_date,et_symptom_other,et_influ_trouble,et_influ_accident,
	et_influ_disaster,et_influ_injure,et_influ_suicide;
	private CheckBox cb_symptom_1,cb_symptom_2,cb_symptom_3,cb_symptom_4,cb_symptom_5,cb_symptom_6,
	cb_symptom_7,cb_symptom_8,cb_symptom_9,cb_symptom_10,cb_symptom_11,cb_symptom_12,cb_influence_1,
	cb_influence_2,cb_influence_3,cb_influence_4,cb_influence_5,cb_influence_6;
	private RadioGroup rg_danger_state,rg_insight,rg_sleep,rg_diet,rg_social_personal_life,
	rg_social_family,rg_social_work,rg_social_study,rg_social_com,rg_lock;
	private RadioButton rb_danger_state_0,rb_danger_state_1,rb_danger_state_2,rb_danger_state_3,
	rb_danger_state_4,rb_danger_state_5,rb_insight_1,rb_insight_2,rb_insight_3,rb_sleep_1,rb_sleep_2,
	rb_sleep_3,rb_diet_1,rb_diet_2,rb_diet_3,rb_social_personal_life_1,rb_social_personal_life_2,
	rb_social_personal_life_3,rb_social_family_1,rb_social_family_2,rb_social_family_3,rb_social_work_1,
	rb_social_work_2,rb_social_work_3,rb_social_work_9,rb_social_study_1,rb_social_study_2,
	rb_social_study_3,rb_social_com_1,rb_social_com_2,rb_social_com_3,rb_lock_1,rb_lock_2,rb_lock_3;
	
	private MyPopupWindow mPopupWindow;
	
	private HereTipa ht;
	private VisitMentals vm;
	private int profileId = 0;
	private int times = 0;
	
	public int getProfileId() {
		return profileId;
	}

	public void setProfileId(int profileId) {
		this.profileId = profileId;
	}

	public int getTimes() {
		return times;
	}

	public void setTimes(int times) {
		this.times = times;
	}

	private View child;
	
	public VisitMentalsView_1(Context context,int profileid,int times) {
		super(context);
		// TODO Auto-generated constructor stub
		this.mContext = context;
		this.profileId = profileid;
		this.times = times;
		
		final LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.visit_record_for_mentals_1, null);
		
	}
	
	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(v==et_date&&hasFocus){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.date), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_symptom_other&&hasFocus){
			cb_symptom_12.setChecked(true);
		}
		else if(v==et_influ_trouble&&hasFocus){
			cb_influence_1.setChecked(true);
		}
		else if(v==et_influ_accident&&hasFocus){
			cb_influence_2.setChecked(true);
		}
		else if(v==et_influ_disaster&&hasFocus){
			cb_influence_3.setChecked(true);
		}
		else if(v==et_influ_injure&&hasFocus){
			cb_influence_4.setChecked(true);
		}
		else if(v==et_influ_suicide&&hasFocus){
			cb_influence_5.setChecked(true);
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_date){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.date), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_symptom_other){
			cb_symptom_12.setChecked(true);
		}
		else if(v==et_influ_trouble){
			cb_influence_1.setChecked(true);
		}
		else if(v==et_influ_accident){
			cb_influence_2.setChecked(true);
		}
		else if(v==et_influ_disaster){
			cb_influence_3.setChecked(true);
		}
		else if(v==et_influ_injure){
			cb_influence_4.setChecked(true);
		}
		else if(v==et_influ_suicide){
			cb_influence_5.setChecked(true);
		}

	}

	/**
	 * 控件与xml文件关联
	 */
	public void findViewsById() {
		et_name = (EditText)child.findViewById(R.id.first_name);
		et_id = (EditText)child.findViewById(R.id.first_id);
		et_date = (EditText)child.findViewById(R.id.date);
		et_date.setInputType(InputType.TYPE_NULL);
		et_date.setOnClickListener(this);
		et_date.setOnFocusChangeListener(this);
		et_symptom_other = (EditText)child.findViewById(R.id.symptom_other);
		et_symptom_other.setOnClickListener(this);
		et_symptom_other.setOnFocusChangeListener(this);
		et_influ_trouble = (EditText)child.findViewById(R.id.influ_trouble);
		et_influ_trouble.setOnClickListener(this);
		et_influ_trouble.setOnFocusChangeListener(this);
		et_influ_accident = (EditText)child.findViewById(R.id.influ_accident);
		et_influ_accident.setOnClickListener(this);
		et_influ_accident.setOnFocusChangeListener(this);
		et_influ_disaster = (EditText)child.findViewById(R.id.influ_disaster);
		et_influ_disaster.setOnClickListener(this);
		et_influ_disaster.setOnFocusChangeListener(this);
		et_influ_injure = (EditText)child.findViewById(R.id.influ_injure);
		et_influ_injure.setOnClickListener(this);
		et_influ_injure.setOnFocusChangeListener(this);
		et_influ_suicide = (EditText)child.findViewById(R.id.influ_suicide);
		et_influ_suicide.setOnClickListener(this);
		et_influ_suicide.setOnFocusChangeListener(this);
		cb_symptom_1 = (CheckBox)child.findViewById(R.id.symptom_1);
		cb_symptom_2 = (CheckBox)child.findViewById(R.id.symptom_2);
		cb_symptom_3 = (CheckBox)child.findViewById(R.id.symptom_3);
		cb_symptom_4 = (CheckBox)child.findViewById(R.id.symptom_4);
		cb_symptom_5 = (CheckBox)child.findViewById(R.id.symptom_5);
		cb_symptom_6 = (CheckBox)child.findViewById(R.id.symptom_6);
		cb_symptom_7 = (CheckBox)child.findViewById(R.id.symptom_7);
		cb_symptom_8 = (CheckBox)child.findViewById(R.id.symptom_8);
		cb_symptom_9 = (CheckBox)child.findViewById(R.id.symptom_9);
		cb_symptom_10 = (CheckBox)child.findViewById(R.id.symptom_10);
		cb_symptom_11 = (CheckBox)child.findViewById(R.id.symptom_11);
		cb_symptom_12 = (CheckBox)child.findViewById(R.id.symptom_12);
		cb_influence_1 = (CheckBox)child.findViewById(R.id.influence_1);
		cb_influence_2 = (CheckBox)child.findViewById(R.id.influence_2);
		cb_influence_3 = (CheckBox)child.findViewById(R.id.influence_3);
		cb_influence_4 = (CheckBox)child.findViewById(R.id.influence_4);
		cb_influence_5 = (CheckBox)child.findViewById(R.id.influence_5);
		cb_influence_6 = (CheckBox)child.findViewById(R.id.influence_6);
		rg_danger_state = (RadioGroup)child.findViewById(R.id.danger_state);
		rg_insight = (RadioGroup)child.findViewById(R.id.insight);
		rg_sleep = (RadioGroup)child.findViewById(R.id.sleep);
		rg_diet = (RadioGroup)child.findViewById(R.id.diet);
		rg_social_personal_life = (RadioGroup)child.findViewById(R.id.social_personal_life);
		rg_social_family = (RadioGroup)child.findViewById(R.id.social_family);
		rg_social_work = (RadioGroup)child.findViewById(R.id.social_work);
		rg_social_study = (RadioGroup)child.findViewById(R.id.social_study);
		rg_social_com = (RadioGroup)child.findViewById(R.id.social_com);
		rg_lock = (RadioGroup)child.findViewById(R.id.lock);
		rb_danger_state_0 = (RadioButton)child.findViewById(R.id.danger_state_0);
		rb_danger_state_1 = (RadioButton)child.findViewById(R.id.danger_state_1);
		rb_danger_state_2 = (RadioButton)child.findViewById(R.id.danger_state_2);
		rb_danger_state_3 = (RadioButton)child.findViewById(R.id.danger_state_3);
		rb_danger_state_4 = (RadioButton)child.findViewById(R.id.danger_state_4);
		rb_danger_state_5 = (RadioButton)child.findViewById(R.id.danger_state_5);
		rb_insight_1 = (RadioButton)child.findViewById(R.id.insight_1);
		rb_insight_2 = (RadioButton)child.findViewById(R.id.insight_2);
		rb_insight_3 = (RadioButton)child.findViewById(R.id.insight_3);
		rb_sleep_1 = (RadioButton)child.findViewById(R.id.sleep_1);
		rb_sleep_2 = (RadioButton)child.findViewById(R.id.sleep_2);
		rb_sleep_3 = (RadioButton)child.findViewById(R.id.sleep_3);
		rb_diet_1 = (RadioButton)child.findViewById(R.id.diet_1);
		rb_diet_2 = (RadioButton)child.findViewById(R.id.diet_2);
		rb_diet_3 = (RadioButton)child.findViewById(R.id.diet_3);
		rb_social_personal_life_1 = (RadioButton)child.findViewById(R.id.social_personal_life_1);
		rb_social_personal_life_2 = (RadioButton)child.findViewById(R.id.social_personal_life_2);
		rb_social_personal_life_3 = (RadioButton)child.findViewById(R.id.social_personal_life_3);
		rb_social_family_1 = (RadioButton)child.findViewById(R.id.social_family_1);
		rb_social_family_2 = (RadioButton)child.findViewById(R.id.social_family_2);
		rb_social_family_3 = (RadioButton)child.findViewById(R.id.social_family_3);
		rb_social_work_1 = (RadioButton)child.findViewById(R.id.social_work_1);
		rb_social_work_2 = (RadioButton)child.findViewById(R.id.social_work_2);
		rb_social_work_3 = (RadioButton)child.findViewById(R.id.social_work_3);
		rb_social_work_9 = (RadioButton)child.findViewById(R.id.social_work_9);
		rb_social_study_1 = (RadioButton)child.findViewById(R.id.social_study_1);
		rb_social_study_2 = (RadioButton)child.findViewById(R.id.social_study_2);
		rb_social_study_3 = (RadioButton)child.findViewById(R.id.social_study_3);
		rb_social_com_1 = (RadioButton)child.findViewById(R.id.social_com_1);
		rb_social_com_2 = (RadioButton)child.findViewById(R.id.social_com_2);
		rb_social_com_3 = (RadioButton)child.findViewById(R.id.social_com_3);
		rb_lock_1 = (RadioButton)child.findViewById(R.id.lock_1);
		rb_lock_2 = (RadioButton)child.findViewById(R.id.lock_2);
		rb_lock_3 = (RadioButton)child.findViewById(R.id.lock_3);
	}
	
	/**
	 * 初始化views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		initialState();
		
		String temp = "";
		int itemp = -1;
		
		temp = ht.getHeti_name();
		if(temp!=null){
			et_name.setText(temp);
		}
		temp = ht.getHeti_here_id();
		if(temp!=null){
			et_id.setText(temp);
		}
		et_name.setEnabled(false);
		et_id.setEnabled(false);
		
		temp = vm.getVime_date();
		if(temp.length()>0){
			et_date.setText(temp);
		}
		itemp = vm.getVime_danger_state();
		switch(itemp){
		case 0:{
			rg_danger_state.check(0);
			rb_danger_state_0.setChecked(true);
			break;
		}
		case 1:{
			rg_danger_state.check(1);
			rb_danger_state_1.setChecked(true);
			break;
		}
		case 2:{
			rg_danger_state.check(2);
			rb_danger_state_2.setChecked(true);
			break;
		}
		case 3:{
			rg_danger_state.check(3);
			rb_danger_state_3.setChecked(true);
			break;
		}
		case 4:{
			rg_danger_state.check(4);
			rb_danger_state_4.setChecked(true);
			break;
		}
		case 5:{
			rg_danger_state.check(5);
			rb_danger_state_5.setChecked(true);
			break;
		}
		}
		
		temp = vm.getVime_symptoms();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:{
					cb_symptom_1.setChecked(true);
					break;
				}
				case 2:{
					cb_symptom_2.setChecked(true);
					break;
				}
				case 3:{
					cb_symptom_3.setChecked(true);
					break;
				}
				case 4:{
					cb_symptom_4.setChecked(true);
					break;
				}
				case 5:{
					cb_symptom_5.setChecked(true);
					break;
				}
				case 6:{
					cb_symptom_6.setChecked(true);
					break;
				}
				case 7:{
					cb_symptom_7.setChecked(true);
					break;
				}
				case 8:{
					cb_symptom_8.setChecked(true);
					break;
				}
				case 9:{
					cb_symptom_9.setChecked(true);
					break;
				}
				case 10:{
					cb_symptom_10.setChecked(true);
					break;
				}
				case 11:{
					cb_symptom_11.setChecked(true);
					break;
				}
				case 12:{
					cb_symptom_12.setChecked(true);
					temp = vm.getVime_symptom_other();
					et_symptom_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = vm.getVime_insight();
		switch(itemp){
		case 1:{
			rg_insight.check(0);
			rb_insight_1.setChecked(true);
			break;
		}
		case 2:{
			rg_insight.check(1);
			rb_insight_2.setChecked(true);
			break;
		}
		case 3:{
			rg_insight.check(2);
			rb_insight_3.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_sleep();
		switch(itemp){
		case 1:{
			rg_sleep.check(0);
			rb_sleep_1.setChecked(true);
			break;
		}
		case 2:{
			rg_sleep.check(1);
			rb_sleep_2.setChecked(true);
			break;
		}
		case 3:{
			rg_sleep.check(2);
			rb_sleep_3.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_diet();
		switch(itemp){
		case 1:{
			rg_diet.check(0);
			rb_diet_1.setChecked(true);
			break;
		}
		case 2:{
			rg_diet.check(1);
			rb_diet_2.setChecked(true);
			break;
		}
		case 3:{
			rg_diet.check(2);
			rb_diet_3.setChecked(true);
			break;
		}
		}

		itemp = vm.getVime_social_personal_life();
		switch(itemp){
		case 1:{
			rg_social_personal_life.check(0);
			rb_social_personal_life_1.setChecked(true);
			break;
		}
		case 2:{
			rg_social_personal_life.check(1);
			rb_social_personal_life_2.setChecked(true);
			break;
		}
		case 3:{
			rg_social_personal_life.check(2);
			rb_social_personal_life_3.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_social_family();
		switch(itemp){
		case 1:{
			rg_social_family.check(0);
			rb_social_family_1.setChecked(true);
			break;
		}
		case 2:{
			rg_social_family.check(1);
			rb_social_family_2.setChecked(true);
			break;
		}
		case 3:{
			rg_social_family.check(2);
			rb_social_family_3.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_social_work();
		switch(itemp){
		case 1:{
			rg_social_work.check(0);
			rb_social_work_1.setChecked(true);
			break;
		}
		case 2:{
			rg_social_work.check(1);
			rb_social_work_2.setChecked(true);
			break;
		}
		case 3:{
			rg_social_work.check(2);
			rb_social_work_3.setChecked(true);
			break;
		}
		case 9:{
			rg_social_work.check(3);
			rb_social_work_9.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_social_study();
		switch(itemp){
		case 1:{
			rg_social_study.check(0);
			rb_social_study_1.setChecked(true);
			break;
		}
		case 2:{
			rg_social_study.check(1);
			rb_social_study_2.setChecked(true);
			break;
		}
		case 3:{
			rg_social_study.check(2);
			rb_social_study_3.setChecked(true);
			break;
		}
		}
		itemp = vm.getVime_social_com();
		switch(itemp){
		case 1:{
			rg_social_com.check(0);
			rb_social_com_1.setChecked(true);
			break;
		}
		case 2:{
			rg_social_com.check(1);
			rb_social_com_2.setChecked(true);
			break;
		}
		case 3:{
			rg_social_com.check(2);
			rb_social_com_3.setChecked(true);
			break;
		}
		}
		
		temp = vm.getVime_influence();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:{
					cb_influence_1.setChecked(true);
					itemp = vm.getVime_influ_trouble();
					if(itemp!=-1){
						et_influ_trouble.setText(String.valueOf(itemp));
					}
					break;
				}
				case 2:{
					cb_influence_2.setChecked(true);
					itemp = vm.getVime_influ_accident();
					if(itemp!=-1){
						et_influ_accident.setText(String.valueOf(itemp));
					}
					break;
				}
				case 3:{
					cb_influence_3.setChecked(true);
					itemp = vm.getVime_influ_disaster();
					if(itemp!=-1){
						et_influ_disaster.setText(String.valueOf(itemp));
					}
					break;
				}
				case 4:{
					cb_influence_4.setChecked(true);
					itemp = vm.getVime_influ_injure();
					if(itemp!=-1){
						et_influ_injure.setText(String.valueOf(itemp));
					}
					break;
				}
				case 5:{
					cb_influence_5.setChecked(true);
					itemp = vm.getVime_influ_suicide();
					if(itemp!=-1){
						et_influ_suicide.setText(String.valueOf(itemp));
					}
					break;
				}
				case 6:{
					cb_influence_6.setChecked(true);
					break;
				}
				}
			}
		}
		itemp = vm.getVime_lock();
		switch(itemp){
		case 1:{
			rg_lock.check(0);
			rb_lock_1.setChecked(true);
			break;
		}
		case 2:{
			rg_lock.check(1);
			rb_lock_2.setChecked(true);
			break;
		}
		case 3:{
			rg_lock.check(2);
			rb_lock_3.setChecked(true);
			break;
		}
		}
	}
	
	/**
	 * 初始时状态：横线为空，所有选择项未选中
	 */
	private void initialState() {
		et_name.setText("");
		et_id.setText("");
		et_date.setText("");
		et_symptom_other.setText("");
		et_influ_trouble.setText("");
		et_influ_accident.setText("");
		et_influ_disaster.setText("");
		et_influ_injure.setText("");
		et_influ_suicide.setText("");
		cb_symptom_1.setChecked(false);
		cb_symptom_2.setChecked(false);
		cb_symptom_3.setChecked(false);
		cb_symptom_4.setChecked(false);
		cb_symptom_5.setChecked(false);
		cb_symptom_6.setChecked(false);
		cb_symptom_7.setChecked(false);
		cb_symptom_8.setChecked(false);
		cb_symptom_9.setChecked(false);
		cb_symptom_10.setChecked(false);
		cb_symptom_11.setChecked(false);
		cb_symptom_12.setChecked(false);
		cb_influence_1.setChecked(false);
		cb_influence_2.setChecked(false);
		cb_influence_3.setChecked(false);
		cb_influence_4.setChecked(false);
		cb_influence_5.setChecked(false);
		cb_influence_6.setChecked(false);
		rb_danger_state_0.setChecked(false);
		rb_danger_state_1.setChecked(false);
		rb_danger_state_2.setChecked(false);
		rb_danger_state_3.setChecked(false);
		rb_danger_state_4.setChecked(false);
		rb_danger_state_5.setChecked(false);
		rb_insight_1.setChecked(false);
		rb_insight_2.setChecked(false);
		rb_insight_3.setChecked(false);
		rb_sleep_1.setChecked(false);
		rb_sleep_2.setChecked(false);
		rb_sleep_3.setChecked(false);
		rb_diet_1.setChecked(false);
		rb_diet_2.setChecked(false);
		rb_diet_3.setChecked(false);
		rb_social_personal_life_1.setChecked(false);
		rb_social_personal_life_2.setChecked(false);
		rb_social_personal_life_3.setChecked(false);
		rb_social_family_1.setChecked(false);
		rb_social_family_2.setChecked(false);
		rb_social_family_3.setChecked(false);
		rb_social_work_1.setChecked(false);
		rb_social_work_2.setChecked(false);
		rb_social_work_3.setChecked(false);
		rb_social_work_9.setChecked(false);
		rb_social_study_1.setChecked(false);
		rb_social_study_2.setChecked(false);
		rb_social_study_3.setChecked(false);
		rb_social_com_1.setChecked(false);
		rb_social_com_2.setChecked(false);
		rb_social_com_3.setChecked(false);
		rb_lock_1.setChecked(false);
		rb_lock_2.setChecked(false);
		rb_lock_3.setChecked(false);
	}
	
	/**
	 * 从数据库中检出数据
	 */
	public void fetchData(){
		ht = new HereTipa(mContext);
		ht.selectNameAndCode(profileId);
		
		vm = new VisitMentals(mContext);
		vm.selectVisitMentals(profileId, times);
	}
	
	/**
	 * 将view添加到父view中
	 */
	public void setMyView(){
		this.removeAllViews();
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
		this.addView(child,lp);
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return child;
	}
	
	/**
	 * 保存views的值到数据库
	 */
	public void saveViews() {
		VisitMentals vms = new VisitMentals(mContext);
		vms.selectVisitMentals(profileId, times);
		
		String temp = "";
		StringBuffer sb;
		
		temp = et_date.getText().toString();
		if(temp.length()>0){
			vms.setVime_date(temp);
		}
		
		if(rb_danger_state_0.isChecked()==true){
			vms.setVime_danger_state(0);
		}else if(rb_danger_state_1.isChecked()==true){
			vms.setVime_danger_state(1);
		}else if(rb_danger_state_2.isChecked()==true){
			vms.setVime_danger_state(2);
		}else if(rb_danger_state_3.isChecked()==true){
			vms.setVime_danger_state(3);
		}else if(rb_danger_state_4.isChecked()==true){
			vms.setVime_danger_state(4);
		}else if(rb_danger_state_5.isChecked()==true){
			vms.setVime_danger_state(5);
		}
		
		sb = new StringBuffer();
		if(cb_symptom_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_symptom_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_symptom_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_symptom_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_symptom_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_symptom_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_symptom_7.isChecked()==true){
			sb.append("7,");
		}
		if(cb_symptom_8.isChecked()==true){
			sb.append("8,");
		}
		if(cb_symptom_9.isChecked()==true){
			sb.append("9,");
		}
		if(cb_symptom_10.isChecked()==true){
			sb.append("10,");
		}
		if(cb_symptom_11.isChecked()==true){
			sb.append("11,");
		}
		if(cb_symptom_12.isChecked()==true){
			sb.append("12,");
			temp = et_symptom_other.getText().toString();
			vms.setVime_symptom_other(temp);
		}
		vms.setVime_symptoms(sb.toString());
		
		if(rb_insight_1.isChecked()==true){
			vms.setVime_insight(1);
		}else if(rb_insight_2.isChecked()==true){
			vms.setVime_insight(2);
		}else if(rb_insight_3.isChecked()==true){
			vms.setVime_insight(3);
		}
		if(rb_sleep_1.isChecked()==true){
			vms.setVime_sleep(1);
		}else if(rb_sleep_2.isChecked()==true){
			vms.setVime_sleep(2);
		}else if(rb_sleep_3.isChecked()==true){
			vms.setVime_sleep(3);
		}
		if(rb_diet_1.isChecked()==true){
			vms.setVime_diet(1);
		}else if(rb_diet_2.isChecked()==true){
			vms.setVime_diet(2);
		}else if(rb_diet_3.isChecked()==true){
			vms.setVime_diet(3);
		}
		
		if(rb_social_personal_life_1.isChecked()==true){
			vms.setVime_social_personal_life(1);
		}else if(rb_social_personal_life_2.isChecked()==true){
			vms.setVime_social_personal_life(2);
		}else if(rb_social_personal_life_3.isChecked()==true){
			vms.setVime_social_personal_life(3);
		}
		if(rb_social_family_1.isChecked()==true){
			vms.setVime_social_family(1);
		}else if(rb_social_family_2.isChecked()==true){
			vms.setVime_social_family(2);
		}else if(rb_social_family_3.isChecked()==true){
			vms.setVime_social_family(3);
		}
		if(rb_social_work_1.isChecked()==true){
			vms.setVime_social_work(1);
		}else if(rb_social_work_2.isChecked()==true){
			vms.setVime_social_work(2);
		}else if(rb_social_work_3.isChecked()==true){
			vms.setVime_social_work(3);
		}else if(rb_social_work_9.isChecked()==true){
			vms.setVime_social_work(9);
		}
		if(rb_social_study_1.isChecked()==true){
			vms.setVime_social_study(1);
		}else if(rb_social_study_2.isChecked()==true){
			vms.setVime_social_study(2);
		}else if(rb_social_study_3.isChecked()==true){
			vms.setVime_social_study(3);
		}
		if(rb_social_com_1.isChecked()==true){
			vms.setVime_social_com(1);
		}else if(rb_social_com_2.isChecked()==true){
			vms.setVime_social_com(2);
		}else if(rb_social_com_3.isChecked()==true){
			vms.setVime_social_com(3);
		}
		
		sb = new StringBuffer();
		if(cb_influence_1.isChecked()==true){
			sb.append("1,");
			temp = et_influ_trouble.getText().toString();
			if(temp.length()>0){
				vms.setVime_influ_trouble(Integer.parseInt(temp));
			}
		}
		if(cb_influence_2.isChecked()==true){
			sb.append("2,");
			temp = et_influ_accident.getText().toString();
			if(temp.length()>0){
				vms.setVime_influ_accident(Integer.parseInt(temp));
			}
		}
		if(cb_influence_3.isChecked()==true){
			sb.append("3,");
			temp = et_influ_disaster.getText().toString();
			if(temp.length()>0){
				vms.setVime_influ_disaster(Integer.parseInt(temp));
			}
		}
		if(cb_influence_4.isChecked()==true){
			sb.append("4,");
			temp = et_influ_injure.getText().toString();
			if(temp.length()>0){
				vms.setVime_influ_injure(Integer.parseInt(temp));
			}
		}
		if(cb_influence_5.isChecked()==true){
			sb.append("5,");
			temp = et_influ_suicide.getText().toString();
			if(temp.length()>0){
				vms.setVime_influ_suicide(Integer.parseInt(temp));
			}
		}
		if(cb_influence_6.isChecked()==true){
			sb.append("6,");
		}
		vms.setVime_influence(sb.toString());
		
		if(rb_lock_1.isChecked()==true){
			vms.setVime_lock(1);
		}else if(rb_lock_2.isChecked()==true){
			vms.setVime_lock(2);
		}else if(rb_lock_3.isChecked()==true){
			vms.setVime_lock(3);
		}
		
		vms.updateVisitMentals(profileId, times);
		
	}

}
